var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/AAA', function(req, res, next) {
	res.render('index', {
		title: 'Express'
	});
});

// 首页数据
router.get('/homeList', function(req, res, next) {
	res.send({
		code: 0,
		data: {
			sortList: [{
				id: 1,
				title: '蔬菜',
				imgUrl: '/images/sort1.png'
			}, {
				id: 2,
				title: '水果',
				imgUrl: '/images/sort2.png'
			}, {
				id: 3,
				title: '豆制品',
				imgUrl: '/images/sort3.png'
			}, {
				id: 4,
				title: '家禽',
				imgUrl: '/images/sort4.png'
			}, {
				id: 5,
				title: '米面油',
				imgUrl: '/images/sort5.png'
			}, {
				id: 6,
				title: '副食',
				imgUrl: '/images/sort6.png'
			}, {
				id: 7,
				title: '冻品',
				imgUrl: '/images/sort7.png'
			}, {
				id: 8,
				title: '调料',
				imgUrl: '/images/sort8.png'
			}, {
				id: 9,
				title: '后厨',
				imgUrl: '/images/sort9.png'
			}, {
				id: 10,
				title: '更多',
				imgUrl: '/images/sort10.png'
			}],
			goodsList: [{
				id: 1,
				name: '红薯叶 每斤',
				imgUrl: '/images/goods-1.jpg',
				server: '',
				price: '1.98',
				icon: '配',
				server: '可代客找车',
			}, {
				id: 2,
				name: '有机胡萝卜 每斤',
				imgUrl: '/images/goods-2.jpg',
				server: '',
				price: '5.98',
				icon: '供',
				server: '全包',
			}, {
				id: 3,
				name: '新疆哈密瓜 每斤',
				imgUrl: '/images/goods-3.png',
				server: '',
				price: '3.54',
				icon: '供',
				server: '全包',
			}, {
				id: 4,
				name: '凯特芒果 每斤',
				imgUrl: '/images/goods-4.png',
				server: '',
				price: '9.9',
				icon: '配',
				server: '可代客装卸',
			}],

		}
	})
})

//搜索页数据
router.get('/searchList', function(req, res, next) {
	res.send({
		code: 0,
		data: {
			Lists: [{
				id: 1,
				name: '红薯叶 每斤',
				imgUrl: '/images/goods-1.jpg',
				server: '',
				price: '1.26',
				icon: '配',
				server: '可代客装卸',
			}, {
				id: 2,
				name: '有机红薯叶 每斤',
				imgUrl: '/images/goods-5.png',
				server: '',
				price: '1.98',
				icon: '配',
				server: '可代客找车',
			}, {
				id: 3,
				name: '新鲜红薯叶 每斤',
				imgUrl: '/images/goods-6.jpg',
				server: '',
				price: '3.71',
				icon: '供',
				server: '全包',
			}, {
				id: 4,
				name: '红薯叶 每斤',
				imgUrl: '/images/goods-1.jpg',
				server: '',
				price: '4.82',
				icon: '供',
				server: '全包',
			}],
		}
	})
})

// 分类接口
router.get('/sortList', function(req, res, next) {
	res.send({
		code: 0,
		data: [{
			// 一级数据（左侧）
			id: 0,
			name: '热门抢购',
			data: [{
					// 二级数据（右侧）
					id: 0,
					name: '哈密瓜',
					imgUrl: '/images/goods-3.png'
				},
				{
					id: 1,
					name: '凯特芒果',
					imgUrl: '/images/goods-4.png'
				},
				{
					id: 2,
					name: '红薯叶',
					imgUrl: '/images/goods-5.png'
				},
				{
					id: 3,
					name: '胡萝卜',
					imgUrl: '/images/goods-2.jpg'
				}
			]
		}, {
			// 一级数据（左侧）
			id: 1,
			name: '蔬菜',
			data: [{
					// 二级数据（右侧）
					id: 0,
					name: '叶菜类',
					imgUrl: '/images/goods-1.jpg'
				},
				{
					id: 1,
					name: '根茎类',
					imgUrl: '/images/goods-2.jpg'
				},
				{
					id: 2,
					name: '茄果类',
					imgUrl: '/images/goods-7.png'
				},
				{
					id: 3,
					name: '菌菇类',
					imgUrl: '/images/goods-8.png'
				}
			]
		}, ]
	})
})

// 从数据库中通过商品id查询对应的商品内容
// router.get('/goods/id', function(req, res, next) {
// 	// 前端传给后端的id
// 	let id = req.query.id
// 	connection.query('select * from goods_list where id=' + id + '',function(error,results){
// 		if(error) throw error
// 		res.json({
// 			code:0,
// 			data:results[0]
// 		})
// 	})

// })


module.exports = router;